import { OnInit, Component, Input, Output, EventEmitter } from '@angular/core';
import { STColumn, STPage, STChange } from '@delon/abc';

@Component({
  selector: 'app-grid-select',
  templateUrl: './grid-select.component.html',
  styles: [],
})
export class GridSelectComponent implements OnInit {
  constructor() {}

  /**
   * 提示
   */
  @Input()
  placeHolder: '请选择';
  /**
   * 显示文本
   */
  @Input()
  gridText = '';
  /**
   * 显示文本类型
   */
  @Input()
  gridTextType = '';

  /**
   * 是否显示下拉列表
   */
  showMenu: boolean;

  // tslint:disable-next-line: no-output-native
  @Output()
  select = new EventEmitter();

  /**
   * 是否禁用控件
   */
  @Input()
  disabled: false;

  /**
   * 列信息
   */
  @Input()
  columns: STColumn[];

  /**
   * 数据
   */
  @Input()
  data: Array<any>;

  @Input()
  scroll = { x: '125%', y: '300px' };

  loading = false;

  /**
   * 分页信息
   */
  page: STPage = {
    front: false,
    show: false,
  };

  gridChange(ret: STChange) {
    if (ret.click) {
      const item = ret.click.item;

      if (this.gridTextType === 'name') {
        this.gridText = item.name;
      } else if (this.gridTextType === 'code') {
        this.gridText = item.code;
      } else if (this.gridTextType === 'courseName') {
        this.gridText = item.course.name;
      }
      //   this.value = this.getJsonValueByField(item, this.fieldValue);
      this.showMenu = false;
      this.select.emit(item);
    }
  }

  ngOnInit() {}
}
